package com.atguigu.tingshu.album.rpc;

import com.atguigu.tingshu.album.service.AlbumInfoService;
import com.atguigu.tingshu.album.service.BaseCategoryService;
import com.atguigu.tingshu.album.service.TrackInfoService;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.AlbumInfo;
import com.atguigu.tingshu.model.album.BaseCategory3;
import com.atguigu.tingshu.model.album.BaseCategoryView;
import com.atguigu.tingshu.model.album.TrackInfo;
import com.atguigu.tingshu.vo.album.AlbumStatVo;
import com.atguigu.tingshu.vo.album.TrackListVo;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/inner/albuminfo")
public class AlbumInfoRpcController {
    @Autowired
    private AlbumInfoService albumInfoService;

    @Autowired
    private BaseCategoryService baseCategoryService;
    @Autowired
    private TrackInfoService trackInfoService;
    @GetMapping("/getAlumInfo/{albumId}")
    @Operation(summary = "根据专辑id获取专辑信息")
    Result<AlbumInfo> getAlumInfo(@PathVariable(value = "albumId") Long albumId){
        return Result.ok(albumInfoService.getAlbumInfo(albumId));
    }

    @GetMapping("/getAlbumInfoCategory/{albumId}")
    @Operation(summary = "根据专辑id获取专辑分类信息")
    Result<BaseCategoryView> getAlbumInfoCategory(@PathVariable(value = "albumId") Long albumId){
        return Result.ok(baseCategoryService.getAlbumInfoCategory(albumId));
    }

    @GetMapping("/getAlbumInfoStat/{albumId}")
    @Operation(summary = "根据专辑id获取专辑的统计信息")
    Result<AlbumStatVo> getAlbumInfoStat(@PathVariable(value = "albumId") Long albumId) {
        return Result.ok(albumInfoService.getAlbumInfoStat(albumId));
    }

    @GetMapping("/getAlbumInfoIdList/{userId}")
    @Operation(summary = "根据用户id获取用户专辑id列表")
    Result<List<Long>> getAlbumInfoIdList(@PathVariable(value = "userId") Long userId){
        return Result.ok(albumInfoService.getAlbumInfoIdList(userId));
    }
    @GetMapping("/getC1Id7TopBaseCategory3List/{c1Id}")
    @Operation(summary = "根据一级分类id获取7个三级分类")
    Result<List<BaseCategory3>> getC1Id7TopBaseCategory3List(@PathVariable(value = "c1Id") Long c1Id){
        return Result.ok(baseCategoryService.findTopBaseCategory3(c1Id));
    }
    @GetMapping("/getCategory1IdList")
    @Operation(summary = "获取一级分类id列表")
    Result<List<Long>> getCategory1IdList(){
        List<Long> c1IdList = baseCategoryService.getCategory1IdList();
        return Result.ok(c1IdList);
    }
    @PostMapping("/getTrackInfoList")
    @Operation(summary = "根据收藏声音id列表获取收藏声音信息列表")
    Result<List<TrackListVo>> getTrackInfoList(@RequestBody List<Long> collectTrackIdList){
        List<TrackListVo> trackInfoVoList =trackInfoService.getTrackInfoList(collectTrackIdList);
        return Result.ok(trackInfoVoList);
    }
    @GetMapping("/getAlbumIds")
    @Operation(summary = "获取专辑id列表")
    Result<List<Long>> getAlbumIds(){
        return Result.ok(albumInfoService.getAlbumIds());
    }
    @GetMapping("/getTrackInfoById/{trackId}")
    @Operation(summary = "根据声音id获取声音信息")
    Result<TrackInfo> getTrackInfoById(@PathVariable(value = "trackId") Long trackId){
        TrackInfo trackInfo = trackInfoService.getTrackInfoById(trackId);
        return Result.ok(trackInfo);
    }
    /*
    综合方法（即能把买过的声音查询出来又能把买过的声音过滤掉 返回真正能买的声音）
    判断购买项是否已经买过（支付完毕）
     */
    @GetMapping("/getPaidTrackAndFilterCanPayTrack/{albumId}/{userId}/{trackCount}/{trackId}")
    @Operation(summary = "根据专辑id、用户id、购买数量、声音id获取买过的声音和真正能买的声音")
    Result<List<TrackInfo>> getPaidTrackAndFilterCanPayTrack(@PathVariable(value = "albumId") Long albumId,@PathVariable(value = "userId") Long userId,@PathVariable(value = "trackCount") Integer trackCount,@PathVariable(value = "trackId") Long trackId){
        return trackInfoService.getPaidTrackAndFilterCanPayTrack(albumId,userId,trackCount,trackId);
    }
}
